#include "Game.h"
#include "Gfx.h"

void save_screen (void)
{

	SDL_Rect rect;
	
	rect.x = 0;
	rect.y = 0;
	rect.w = game.screen->w;
	rect.h = game.screen->h;

	SDL_BlitSurface (game.screen, &rect, game.screen_buffer, &rect);
	
}

void restore_screen (void)
{

	SDL_Rect rect;

	rect.x = 0;
	rect.y = 0;
	rect.w = game.screen->w;
	rect.h = game.screen->h;

	SDL_BlitSurface (game.screen_buffer, &rect, game.screen, &rect);
	addRect (rect.x, rect.y, rect.w, rect.h);

}


void flash (int r, int g, int b, Uint32 ms, int repeat)
{
	flash2 (r, g, b, ms, ms, repeat);
}

void flash2 (int r, int g, int b, Uint32 msclear, Uint32 msflash, int repeat)
{

	Uint32 color;
	int k;

	color = SDL_MapRGB(game.screen->format, r,g,b);

	save_screen();

	for ( k = 0; k < repeat; k++ )
	{	
		SDL_FillRect (game.screen, (SDL_Rect *)0, color);
		SDL_Flip(game.screen);
		SDL_Delay(msflash);
		restore_screen();
		SDL_Flip(game.screen);
		SDL_Delay(msclear);
	}

}


